package com.youkeda.meetingroom.service.impl;

import com.youkeda.meetingroom.dao.dataobject.MrMeetingRoom;
import com.youkeda.meetingroom.dao.mapper.MrMeetingRoomMapper;
import com.youkeda.meetingroom.model.MeetingRoom;
import com.youkeda.meetingroom.model.Result;
import com.youkeda.meetingroom.service.MeetingRoomService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * MeetingRoomServiceImpl的注释
 *
 * @author: Awake
 * @date: 2019-07-03 17:35
 **/
@Service
public class MeetingRoomServiceImpl implements MeetingRoomService {
    /**
     * 获取会议室的详细信息
     *
     * @param meetingRoomId 会议室主键
     * @return 会议室的详细信息
     */
    @Resource
    MrMeetingRoomMapper mrMeetingRoomMapper;
    
    @Override
    public Result getMeetingRoomInfo(String meetingRoomId) {
        Result result = new Result();
        MeetingRoom meetingRoom = new MeetingRoom();
        MrMeetingRoom mrMeetingRoom = mrMeetingRoomMapper.selectByPrimaryKey(meetingRoomId);
        if (mrMeetingRoom != null) {
            BeanUtils.copyProperties(mrMeetingRoom, meetingRoom);
            if(!meetingRoom.isBeBooked() && !meetingRoom.isInMaintenance() && !meetingRoom.isInUse()){
                meetingRoom.setValid(true);
            }
            else {
                meetingRoom.setValid(false);
            }
            result.setSuccess(true);
            result.setData(meetingRoom);
        }else{
            result.setSuccess(false);
            result.setErrorMessage("未找到相应的会议室");
        }
        return result;

    }
}
